package com.video.controller;

import com.common.result.Result;
import com.common.utils.AliOSSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author 路亚
 * @version 0.1
 * @className UploadController
 * @description
 * @date 2024/12/13 14:56
 * @since jdk11
 */
@RestController
@RequestMapping("/upload")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "上传文件管理")
public class UploadController {

    private final AliOSSUtils aliOSSUtils;

    @PostMapping("/upload/cover")
    @ApiOperation("上传封面")
    public Result uploadCover(MultipartFile file) throws IOException {
        log.info("上传封面,file:{}", file);
        String url = aliOSSUtils.upload(file);
        return Result.success(url);
    }

    @PostMapping("/upload/video")
    @ApiOperation("上传视频")
    public Result uploadVideo(MultipartFile file) throws IOException {
        log.info("上传视频,file:{}", file);
        String url = aliOSSUtils.upload(file);
        return Result.success(url);
    }
}
